package com.atguigu.test06;

import com.atguigu.test06.bean.Employee;

import java.util.List;

/**
 * @author haoranlu
 * @project IntelliJ IDEA
 */
public class EmployeeDAOImp1 extends BasicDAOImp1<Employee> implements EmployeeDAO{

    @Override
    public void addEmployee(Employee emp) {
        String sql = "insert into employee values(null,?,?,?,?)";
        try {
            update(sql,emp.getName(),emp.getSex(),emp.getTitle(),emp.getBirthday());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void updateEmployee(Employee emp) {
        String sql = "update employee set name=?,sex=?,title=?,birthday=? where empid = ?";
        try {
            update(sql,emp.getName(),emp.getSex(),emp.getTitle(),emp.getBirthday(),emp.getEmpid());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void deleteEmployee(int empid) {
        String sql = "delete from employee where empid=? ";
        try {
            update(sql,empid);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public Employee getById(int empid) {
        String sql = "select * from employee where empid = ?";
        Employee emp = null;
        try {
            emp = getBean(sql, empid);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return emp;
    }

    @Override
    public List<Employee> getAll() {
        String sql = "select * from employee";
        List<Employee> list = null;
        try {
            list=getBeanList(sql);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return list;
    }
}
